#include <arm/types.h>

#include "lcd_util.h"
#define delay delay_ms

/* these inits are thought to be for an ILI932x */

void LCD_SetGRAM(int scan_dir) {
	/* //--- Set GRAM Area ---// */
	LCD_CtrlWrite(0x50, 0x0000);
	LCD_CtrlWrite(0x51, 0x00EF);
	LCD_CtrlWrite(0x52, 0x0000);
	LCD_CtrlWrite(0x53, 0x013F);
	LCD_CtrlWrite(0x60, scan_dir?0xA700:0x2700);
	LCD_CtrlWrite(0x61, 0x0001);
	LCD_CtrlWrite(0x6A, 0x0000);	
}

void LCD_SetPDisplay(int ram_end_addr) {
	/* //--- Partial display control ---// */
	LCD_CtrlWrite(0x80, 0);
	LCD_CtrlWrite(0x81, 0);
	LCD_CtrlWrite(0x82, 0);
	LCD_CtrlWrite(0x83, ram_end_addr);
	LCD_CtrlWrite(0x84, 0);
	LCD_CtrlWrite(0x85, ram_end_addr);
}

void LCD_Init_3(void) { /* untested */
	uint16_t gamma[] = {6, 0x407, 0x200, 7, 0xf07, 0x506, 0x203, 0x607, 0x601, 0x1f00};
	/* //--- Init sequence ---// */
	LCD_CtrlWrite(0xE5, 0x8000);
	
	LCD_CtrlWrite(0x00, 0x0001);
	LCD_CtrlWrite(0x01, 0x0100);
	LCD_CtrlWrite(0x02, 0x0700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0000);
	LCD_CtrlWrite(0x08, 0x0202);
	LCD_CtrlWrite(0x09, 0x0000);
	LCD_CtrlWrite(0x0A, 0x0000);
	LCD_CtrlWrite(0x0C, 0x0000);
	LCD_CtrlWrite(0x0D, 0x0000);
	LCD_CtrlWrite(0x0F, 0x0000);
	
	/* //--- Power on sequence ---// */
	LCD_CtrlWrite(0x10, 0x0000);
	LCD_CtrlWrite(0x11, 0x0007);
	LCD_CtrlWrite(0x12, 0x0000);
	LCD_CtrlWrite(0x13, 0x0000);
	delay_ms(200);
	LCD_CtrlWrite(0x10, 0x17B0);
	LCD_CtrlWrite(0x11, 0x0137);
	delay_ms(50);
	LCD_CtrlWrite(0x12, 0x013C);
	delay_ms(50);
	LCD_CtrlWrite(0x13, 0x1800);
	LCD_CtrlWrite(0x29, 0x0016);
	delay_ms(50);
	LCD_CtrlWrite(0x20, 0x0000);
	LCD_CtrlWrite(0x21, 0x0000);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(0);
	
	LCD_SetPDisplay(0);
	
	/*  //--- Panel Control ---// */
	LCD_CtrlWrite(0x90, 0x0010);
	LCD_CtrlWrite(0x92, 0x0000);
	LCD_CtrlWrite(0x93, 0x0003);
	LCD_CtrlWrite(0x95, 0x0110);
	LCD_CtrlWrite(0x97, 0x0000);
	LCD_CtrlWrite(0x98, 0x0000);
	LCD_CtrlWrite(0x07, 0x0173);
}

void LCD_Init_3b(void) { /* tested by Inopia */
	uint16_t gamma[] = {6, 0x407, 0x200, 7, 0xf07, 0x506, 0x203, 0x607, 0x601, 0x1f00};
	/* //--- Init sequence ---// */
	LCD_CtrlWrite(0xE5, 0x8000);
	
	LCD_CtrlWrite(0x00, 0x0001);
	LCD_CtrlWrite(0x01, 0x0100);
	LCD_CtrlWrite(0x02, 0x0700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0000);
	LCD_CtrlWrite(0x08, 0x0202);
	LCD_CtrlWrite(0x09, 0x0000);
	LCD_CtrlWrite(0x0A, 0x0000);
	LCD_CtrlWrite(0x0C, 0x0000);
	LCD_CtrlWrite(0x0D, 0x0000);
	LCD_CtrlWrite(0x0F, 0x0000);
	
	/* //--- Power on sequence ---// */
	LCD_CtrlWrite(0x10, 0x0000);
	LCD_CtrlWrite(0x11, 0x0007);
	LCD_CtrlWrite(0x12, 0x0000);
	LCD_CtrlWrite(0x13, 0x0000);
	delay_ms(200);
	LCD_CtrlWrite(0x10, 0x17B0);
	LCD_CtrlWrite(0x11, 0x0137);
	delay_ms(50);
	LCD_CtrlWrite(0x12, 0x013C);
	delay_ms(50);
	LCD_CtrlWrite(0x13, 0x1800);
	LCD_CtrlWrite(0x29, 0x0016);
	delay_ms(50);
	LCD_CtrlWrite(0x20, 0x0000);
	LCD_CtrlWrite(0x21, 0x0000);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(0);
	LCD_SetPDisplay(0);
	
	/*  //--- Panel Control ---// */
	LCD_CtrlWrite(0x90, 0x0010);
	LCD_CtrlWrite(0x92, 0x0000);
	LCD_CtrlWrite(0x93, 0x0003);
	LCD_CtrlWrite(0x95, 0x0110);
	LCD_CtrlWrite(0x97, 0x0000);
	LCD_CtrlWrite(0x98, 0x0000);
	LCD_CtrlWrite(0x07, 0x0173);
}


void lcd_init_1(void) { /* untested */
	uint16_t gamma[] = {0, 0x306, 0x200, 0x107, 0x404, 0x606, 0x105, 0x707, 0x600, 0x807};
	LCD_CtrlWrite(0x00, 0x1);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x03, 0x1038);
	LCD_CtrlWrite(0x03, 0x10b0);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x202);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(25);
	LCD_CtrlWrite(0x10, 0x17b0);
	LCD_CtrlWrite(0x11, 0x1);
	delay(25);
	LCD_CtrlWrite(0x12, 0x13c);
	delay(25);
	LCD_CtrlWrite(0x13, 0x1300);
	LCD_CtrlWrite(0x29, 0x4);
	delay(25);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	LCD_CtrlWrite(0x2b, 0x20);

	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(0);
	LCD_SetPDisplay(0);

	LCD_CtrlWrite(0x90, 0x13);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x3);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0x07, 0x1);
	delay(25);
	LCD_CtrlWrite(0x07, 0x21);
	LCD_CtrlWrite(0x07, 0x23);
	delay(25);
	LCD_CtrlWrite(0x07, 0x173);
	delay(200);
}

void lcd_init_1b(void) { /* bushing */
	uint16_t gamma[] = {6, 0x407, 0x200, 7, 0xf07, 0x506, 0x203, 0x607, 0x601, 0x1f00};
	
	LCD_CtrlWrite(0x00, 0x1);	/* start oscillation */
	LCD_CtrlWrite(0x01, 0x100);	/* driver output order: 720 .. 1 */
	LCD_CtrlWrite(0x03, 0x1090);/* pixel order: BGR=1 ORG=1 I/D=01 */
	LCD_CtrlWrite(0x04, 0x0);	/* disable resizing */
	LCD_CtrlWrite(0x08, 0x202); /* front porch = 2 lines, back porch = 2 lines */

	LCD_CtrlWrite(0x10, 0x17b0); /* wake up:
	 								SAP=1 Source output driver enabled
									BT=7 step-up factor
									APE=1 Power supply enable
									AP=3 Current adj = 1:1 */
	LCD_CtrlWrite(0x11, 0x1);	/* VCiOUT = 0.89 * VCi */
	LCD_CtrlWrite(0x12, 0x18);	/* VCMR=0, PON=1, VREG1OUT=VCILvl*1.8 */
	LCD_CtrlWrite(0x13, 0x1300);/* set VCOM = VREG1OUT * 0.94 */
	LCD_CtrlWrite(0x29, 0x4);	/* set VcomH = VREG1OUT * 0.73 */

	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);

	/* next value effectively sets screen height! */
	LCD_CtrlWrite(0x90, 0x3c);	/* set clocks/line (internal clock mode)*/
	LCD_CtrlWrite(0x92, 0x0);	/* set gate non-overlap period = 0 clocks */
	LCD_CtrlWrite(0x93, 0x3);	/* set source output position = 3 clocks */
	LCD_CtrlWrite(0x95, 0x110); /* set clocks/line (RGB iface mode) */
#if 0
	LCD_CtrlWrite(0x07, 0x1);   /* enable GRAM */
	LCD_CtrlWrite(0x07, 0x23);  /* output black, screen on */
#endif
	LCD_CtrlWrite(0x07, 0x133); /* enable BASEE */
}

void lcd_init_9(void) { /* untested */
	uint16_t gamma[] = {0, 0x504, 3, 0x303, 0x1210, 0x406, 0x506, 0x707, 0x304, 0x1012};
	LCD_CtrlWrite(0x00, 0x0);
	LCD_CtrlWrite(0x00, 0x0);
	LCD_CtrlWrite(0x00, 0x0);
	LCD_CtrlWrite(0x00, 0x0);
	LCD_CtrlWrite(0x2b, 0x3);
	LCD_CtrlWrite(0x00, 0x1);
	delay(500);
	LCD_CtrlWrite(0x07, 0x0);
	delay(500);
	LCD_CtrlWrite(0x12, 0x0);
	delay(500);
	LCD_CtrlWrite(0x08, 0x405);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	
	LCD_CtrlWrite(0x10, 0x2c0);
	LCD_CtrlWrite(0x11, 0x242);
	delay(300);
	LCD_CtrlWrite(0x12, 0x118);
	delay(300);
	LCD_CtrlWrite(0x13, 0x800);
	LCD_CtrlWrite(0x29, 0x0);
	delay(300);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x5030);
	LCD_CtrlWrite(0x90, 0x110);
	LCD_CtrlWrite(0x92, 0x0);
	
	LCD_SetPDisplay(0x13f);
	LCD_CtrlWrite(0x98, 0x202);
	LCD_CtrlWrite(0x10, 0x12f0);
	delay(200);
	LCD_CtrlWrite(0x07, 0x133);
}

void lcd_init_11(void) { /* untested */
	uint16_t gamma[] = {4, 0x307, 2, 0x206, 0x408, 0x507, 0x204, 0x707, 0x405, 0xf02};
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	delay(1000);
	LCD_CtrlWrite(0x00, 0x1);
	delay(1000);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1020);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x3);
	delay(25);
	LCD_CtrlWrite(0x10, 0x1290);
	LCD_CtrlWrite(0x11, 0x227);
	delay(25);
	LCD_CtrlWrite(0x12, 0x1b);
	delay(25);
	LCD_CtrlWrite(0x13, 0x1503);
	LCD_CtrlWrite(0x29, 0x3);
	delay(25);
	LCD_CtrlWrite(0x2b, 0xd);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);
	
	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x3);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0x07, 0x133);
	delay(200);
}

void lcd_init_12(void) { /* untested */
	uint16_t gamma[] = {0x204, 0x507, 0x204, 0x107, 0x207, 0x305, 2, 0x305, 0x701, 0x60a};
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(200);
	LCD_CtrlWrite(0x10, 0x1290);
	LCD_CtrlWrite(0x11, 0x227);
	delay(50);
	LCD_CtrlWrite(0x12, 0x1a);
	delay(50);
	LCD_CtrlWrite(0x13, 0x1600);
	LCD_CtrlWrite(0x29, 0x1d);
	LCD_CtrlWrite(0x2b, 0xb);
	delay(50);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);

	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);

	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x600);
	LCD_CtrlWrite(0x93, 0x3);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0x07, 0x133);
	delay(200);
}

void lcd_init_13(void) { /* untested */
	uint16_t gamma[] = {0x305, 0x307, 3, 4, 0x302, 0x407, 4, 0x204, 0x307, 0xc};
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(200);
	LCD_CtrlWrite(0x10, 0x1490);
	LCD_CtrlWrite(0x11, 0x227);
	delay(50);
	LCD_CtrlWrite(0x12, 0x19);
	delay(50);
	LCD_CtrlWrite(0x13, 0xa00);
	LCD_CtrlWrite(0x29, 0x1);
	LCD_CtrlWrite(0x2b, 0xd);
	delay(50);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);

	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x600);
	LCD_CtrlWrite(0x93, 0x3);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0x07, 0x133);
	delay(200);
}

void lcd_init_14(void) { /* untested */
	uint16_t gamma[] = {0, 0x406, 4, 0x305, 4, 0x207, 0x103, 0x707, 0x503, 4};
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x202);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(200);
	LCD_CtrlWrite(0x10, 0x1290);
	LCD_CtrlWrite(0x11, 0x227);
	delay(50);
	LCD_CtrlWrite(0x12, 0x1b);
	delay(50);
	LCD_CtrlWrite(0x13, 0x1200);
	LCD_CtrlWrite(0x29, 0x0);
	LCD_CtrlWrite(0x2b, 0xc);
	delay(50);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);

	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x600);
	LCD_CtrlWrite(0x07, 0x133);
	delay(200);
}

void lcd_init_17(void) { /* untested */
	uint16_t gamma[] = {0, 0x505, 7, 0x502, 0x807, 7, 0x202, 0x707, 0x205, 0x608};
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(200);
	LCD_CtrlWrite(0x10, 0x1490);
	LCD_CtrlWrite(0x11, 0x227);
	delay(50);
	LCD_CtrlWrite(0x12, 0x1a);
	delay(50);
	LCD_CtrlWrite(0x13, 0x1400);
	LCD_CtrlWrite(0x29, 0x16);
	LCD_CtrlWrite(0x2b, 0xd);
	delay(50);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);

	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x3);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0x07, 0x133);
	delay(200);
}

void lcd_init_18(void) { /* untested */
	uint16_t gamma[] = {0, 0x507, 4, 0x205, 4, 0x307, 2, 0x707, 0x502, 4};
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x202);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(200);
	LCD_CtrlWrite(0x10, 0x1690);
	LCD_CtrlWrite(0x11, 0x227);
	delay(50);
	LCD_CtrlWrite(0x12, 0x1b);
	delay(50);
	LCD_CtrlWrite(0x13, 0x1800);
	LCD_CtrlWrite(0x29, 0x21);
	LCD_CtrlWrite(0x2b, 0x8);
	delay(50);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);
	
	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x3);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0x07, 0x133);
	delay(200);
}

void lcd_init_20(void) { /* untested */
	uint16_t gamma[] = {0, 0x406, 4, 0x305, 4, 0x207, 0x103, 0x707, 0x503, 4};
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x202);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(200);
	LCD_CtrlWrite(0x10, 0x1290);
	LCD_CtrlWrite(0x11, 0x227);
	delay(50);
	LCD_CtrlWrite(0x12, 0x1a);
	delay(50);
	LCD_CtrlWrite(0x13, 0x1400);
	LCD_CtrlWrite(0x29, 0x1f);
	LCD_CtrlWrite(0x2b, 0xc);
	delay(50);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);

	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);

	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x600);
	LCD_CtrlWrite(0x07, 0x133);
	delay(200);
}

void lcd_init_23(void) { /* untested */
	uint16_t gamma[] = {7, 0x604, 7, 0x503, 0x808, 7, 0x301, 7, 0x305, 0x808};
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x202);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(32000);
	LCD_CtrlWrite(0x10, 0x1690);
	LCD_CtrlWrite(0x11, 0x227);
	delay(8000);
	LCD_CtrlWrite(0x12, 0x1a);
	delay(8000);
	LCD_CtrlWrite(0x13, 0x1600);
	LCD_CtrlWrite(0x29, 0x29);
	LCD_CtrlWrite(0x2b, 0xd);
	delay(8000);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);

	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x3);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0x07, 0x133);
}

void lcd_init_25(void) { /* untested */
	uint16_t gamma[] = {0x301, 0x107, 0x301, 3, 0, 0, 0x706, 0x206, 4, 0};
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x08, 0x302);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x8);
	delay(1);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x5);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(1);
	LCD_CtrlWrite(0x10, 0x12b0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x8a);
	LCD_CtrlWrite(0x13, 0x1900);
	LCD_CtrlWrite(0x29, 0x34);
	delay(1);
	LCD_CtrlWrite(0x75, 0x0);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	
	LCD_CtrlWrite(0x90, 0x30);
	delay(1);
	LCD_CtrlWrite(0x07, 0x133);
	delay(200);
}

void lcd_init_26_29(void) { /* untested */
	uint16_t gamma[] = {0, 0x700, 0x707, 7, 0, 0x607, 0x206, 1, 0x700, 0};
	LCD_CtrlWrite(0x00, 0x1);
	delay(1600);
	LCD_CtrlWrite(0x10, 0x130);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	LCD_CtrlWrite(0x29, 0x0);
	LCD_CtrlWrite(0x15, 0x1113);
	delay(1600);
	LCD_CtrlWrite(0x10, 0x1b0);
	LCD_CtrlWrite(0x11, 0x222);
	delay(1600);
	LCD_CtrlWrite(0x12, 0x10);
	delay(8000);
	LCD_CtrlWrite(0x15, 0x103);
	delay(16000);
	LCD_CtrlWrite(0x10, 0xd0);
	delay(8000);
	LCD_CtrlWrite(0x12, 0x9b);
	LCD_CtrlWrite(0x29, 0x28);
	LCD_CtrlWrite(0x13, 0x1300);
	delay(1600);
	LCD_CtrlWrite(0x03, 0x1090);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	LCD_CtrlWrite(0x2b, 0x0);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x300);
	LCD_CtrlWrite(0x2b, 0x8);
	LCD_CtrlWrite(0x08, 0x808);
	LCD_CtrlWrite(0x09, 0x1);
	LCD_CtrlWrite(0x0a, 0x8);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0f, 0x3);
	
	LCD_SetGRAM(1);
	
	/* should be special-cased in LCD_SetGRAM? */
	LCD_CtrlWrite(0x60, 0x3100);
	
	LCD_SetPDisplay(0);

	LCD_CtrlWrite(0x90, 0x0);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x0);

	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);

	LCD_CtrlWrite(0x10, 0x10b0);
	LCD_CtrlWrite(0x07, 0x101);
	delay(8000);
	LCD_CtrlWrite(0x07, 0x121);
	LCD_CtrlWrite(0x07, 0x123);
	delay(8000);
	LCD_CtrlWrite(0x07, 0x133);
	delay(1600);
}

void lcd_init_32(void) { /* untested */
	uint16_t gamma[] = {0, 0x106, 0, 0x204, 0x160a, 0x707, 0x106, 0x706, 0x402, 0xc0f};
	LCD_CtrlWrite(0xe7, 0x1014);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x200);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x08, 0x202);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(16000);
	LCD_CtrlWrite(0x10, 0x1690);
	LCD_CtrlWrite(0x11, 0x227);
	delay(8000);
	LCD_CtrlWrite(0x12, 0xc);
	delay(8000);
	LCD_CtrlWrite(0x13, 0x500);
	LCD_CtrlWrite(0x29, 0x11);
	LCD_CtrlWrite(0x2b, 0xb);
	delay(8000);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(0);
	LCD_SetPDisplay(0);
	
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);

	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x600);
	LCD_CtrlWrite(0x07, 0x133);
	delay(200);
}

void lcd_init_33(void) { /* untested */
	uint16_t gamma[] = {0, 0x507, 1, 0x101, 0x18e0, 0x607, 5, 0x707, 0x100, 0x101};
	LCD_CtrlWrite(0x2b, 0x3);
	LCD_CtrlWrite(0x00, 0x1);
	delay(2);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x07, 0x0);
	delay(2);
	LCD_CtrlWrite(0x12, 0x0);
	delay(2);
	LCD_CtrlWrite(0x08, 0x405);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);

	LCD_CtrlWrite(0x10, 0x290);
	LCD_CtrlWrite(0x11, 0x247);
	delay(5);
	LCD_CtrlWrite(0x12, 0x118);
	delay(5);
	LCD_CtrlWrite(0x13, 0xe00);
	delay(2);
	LCD_CtrlWrite(0x29, 0x2a);
	delay(2);
	LCD_CtrlWrite(0x90, 0x110);
	LCD_CtrlWrite(0x92, 0x0);

	LCD_SetPDisplay(0x13f);

	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	LCD_CtrlWrite(0x98, 0x202);
	LCD_CtrlWrite(0x10, 0x12f0);
	delay(2);
	LCD_CtrlWrite(0x07, 0x133);
	delay(200);
}

void lcd_init_34(void) { /* untested */
	uint16_t gamma[] = {0, 0x607, 0x305, 0, 0x1604, 0x204, 1, 0x707, 0, 0xf};
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(1600);
	LCD_CtrlWrite(0x10, 0x1490);
	LCD_CtrlWrite(0x11, 0x227);
	delay(1600);
	LCD_CtrlWrite(0x12, 0x1a);
	delay(1600);
	LCD_CtrlWrite(0x13, 0x700);
	LCD_CtrlWrite(0x29, 0x7);
	LCD_CtrlWrite(0x2b, 0xc);
	delay(1600);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);
	
	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x600);
	LCD_CtrlWrite(0x07, 0x133);
	delay(1600);
}

void lcd_init_35(void) { /* untested */
	uint16_t gamma[] = {4, 0x607, 6, 0x302, 4, 0x107, 1, 0x307, 0x203, 4};
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	LCD_CtrlWrite(0x07, 0x1);
	delay(1600);
	LCD_CtrlWrite(0x10, 0x1290);
	LCD_CtrlWrite(0x11, 0x227);
	delay(1600);
	LCD_CtrlWrite(0x12, 0x1a);
	delay(1600);
	LCD_CtrlWrite(0x13, 0x700);
	LCD_CtrlWrite(0x29, 0xc);
	LCD_CtrlWrite(0x2b, 0xf);
	delay(1600);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);
	
	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x600);
	LCD_CtrlWrite(0x07, 0x133);
	delay(200);
}

void lcd_init_36(void) { /* untested */
	uint16_t gamma[] = {0, 6, 0x100, 1, 0, 0, 0x406, 0x202, 1, 0};
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x08, 0x807);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x10, 0x790);
	LCD_CtrlWrite(0x11, 0x5);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x13, 0x0);
	delay(100);
	LCD_CtrlWrite(0x10, 0x1490);
	delay(50);
	LCD_CtrlWrite(0x11, 0x227);
	delay(50);
	LCD_CtrlWrite(0x12, 0x89);
	LCD_CtrlWrite(0x13, 0x1900);
	LCD_CtrlWrite(0x29, 0x21);

	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);

	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	LCD_CtrlWrite(0x90, 0x33);
	LCD_CtrlWrite(0x07, 0x133);
	delay(50);
	LCD_AddrWrite(0x22);
}

void lcd_init_38(void) { /* untested */
	uint16_t gamma[] = {0, 0x305, 1, 0x302, 0x1f00, 0x204, 0x201, 0x707, 0x202, 0x1f06};
	LCD_CtrlWrite(0x2b, 0x3);
	LCD_CtrlWrite(0x00, 0x1);
	delay(3200);
	LCD_CtrlWrite(0x07, 0x0);
	LCD_CtrlWrite(0x11, 0x777);
	delay(1600);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x08, 0x405);
	LCD_CtrlWrite(0x01, 0x100);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	
	LCD_CtrlWrite(0x10, 0x4c0);
	LCD_CtrlWrite(0x12, 0x118);
	LCD_CtrlWrite(0x11, 0x737);
	delay(16000);
	LCD_CtrlWrite(0x11, 0x237);
	LCD_CtrlWrite(0x13, 0xc00);
	LCD_CtrlWrite(0x29, 0x2a);
	delay(3200);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x90, 0x10e);
	LCD_CtrlWrite(0x91, 0x300);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x98, 0x262);
	LCD_SetPDisplay(0x13f);
	LCD_CtrlWrite(0x10, 0x14c0);
	delay(3200);
	LCD_CtrlWrite(0x07, 0x133);
	delay(1);
}

void lcd_init_39(void) { /* untested */
	uint16_t gamma[] = {0, 0x503, 0x105, 0x300, 0x1f00, 0x306, 0x503, 0x707, 2, 0x1f06};
	LCD_CtrlWrite(0x2b, 0x3);
	LCD_CtrlWrite(0x00, 0x1);
	delay(3200);
	LCD_CtrlWrite(0x07, 0x0);
	LCD_CtrlWrite(0x11, 0x777);
	delay(1600);
	LCD_CtrlWrite(0x12, 0x0);
	LCD_CtrlWrite(0x08, 0x405);
	LCD_CtrlWrite(0x01, 0x100);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(1);
	
	LCD_CtrlWrite(0x10, 0x4c0);
	LCD_CtrlWrite(0x12, 0x118);
	LCD_CtrlWrite(0x11, 0x737);
	delay(16000);
	LCD_CtrlWrite(0x11, 0x237);
	LCD_CtrlWrite(0x13, 0xc00);
	LCD_CtrlWrite(0x29, 0x2a);
	delay(3200);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x90, 0x10d);
	LCD_CtrlWrite(0x91, 0x300);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x98, 0x262);
	LCD_SetPDisplay(0x13f);
	LCD_CtrlWrite(0x10, 0x14c0);
	delay(3200);
	LCD_CtrlWrite(0x07, 0x133);
}

void lcd_init_40(void) { /* untested */
	uint16_t gamma[] = {0x402, 6, 0, 0, 0x600, 0x507, 0x707, 0, 0x803, 0x308};
	LCD_CtrlWrite(0xb0, 0x0);
	LCD_CtrlWrite(0x00, 0x1);
	delay(50);
	LCD_CtrlWrite(0x07, 0x0);
	delay(50);
	LCD_CtrlWrite(0x12, 0x0);
	delay(50);
	LCD_CtrlWrite(0x70, 0x3f00);
	LCD_CtrlWrite(0x08, 0x405);
	
	/* //--- Adjust the Gamma Curve ---// */
	LCD_SetGamma(gamma);
	LCD_SetGRAM(0); /* 61 was never written? */
	
	LCD_CtrlWrite(0x15, 0x1);
	LCD_CtrlWrite(0x10, 0x67b0);
	LCD_CtrlWrite(0x11, 0x47);
	delay(30);
	LCD_CtrlWrite(0x12, 0x117);
	delay(30);
	LCD_CtrlWrite(0x13, 0xa718);
	delay(30);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x4030);
	LCD_CtrlWrite(0x71, 0x0);
	LCD_CtrlWrite(0x90, 0x108);
	LCD_CtrlWrite(0x91, 0x0);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_SetPDisplay(0x13f);
	LCD_CtrlWrite(0x10, 0x77b0);
	delay(20);
	LCD_CtrlWrite(0x12, 0x1111);
	delay(20);
	LCD_CtrlWrite(0x07, 0x3233);
}

/* These bear some similarity to the above sequences, but don't quite match */

void lcd_init_10(void) { /* untested */
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x12b0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x17, 0x1);
	LCD_CtrlWrite(0x12, 0x1bb);
	LCD_CtrlWrite(0x13, 0x1c00);
	delay(200);
	LCD_CtrlWrite(0x29, 0x12);
	delay(50);
	LCD_CtrlWrite(0x30, 0xb0d);
	LCD_CtrlWrite(0x31, 0x1921);
	LCD_CtrlWrite(0x32, 0x1c25);
	LCD_CtrlWrite(0x33, 0x251c);
	LCD_CtrlWrite(0x34, 0x2119);
	LCD_CtrlWrite(0x35, 0xd0b);
	LCD_CtrlWrite(0x36, 0xf06);
	LCD_CtrlWrite(0x37, 0x60f);
	LCD_CtrlWrite(0x38, 0x705);
	LCD_CtrlWrite(0x39, 0x304);
	LCD_CtrlWrite(0x3a, 0xe05);
	LCD_CtrlWrite(0x3b, 0xe01);
	LCD_CtrlWrite(0x3c, 0x10e);
	LCD_CtrlWrite(0x3d, 0x50e);
	LCD_CtrlWrite(0x3e, 0x303);
	LCD_CtrlWrite(0x3f, 0x507);

	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);
	LCD_CtrlWrite(0x90, 0x16);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x103);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0xf0, 0x5408);
	LCD_CtrlWrite(0xe0, 0x1);
	LCD_CtrlWrite(0xf2, 0xdf);
	LCD_CtrlWrite(0xf3, 0x6d06);
	LCD_CtrlWrite(0xf4, 0x17);
	LCD_CtrlWrite(0xf0, 0x0);
	LCD_CtrlWrite(0x10, 0x12b0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x138);
	LCD_CtrlWrite(0x13, 0x1300);
	LCD_CtrlWrite(0x29, 0xb);
	delay(20);
	LCD_CtrlWrite(0x07, 0x112);
	delay(200);
}

void lcd_init_21(void) { /* untested */
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x12b0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x17, 0x1);
	LCD_CtrlWrite(0x12, 0x1bb);
	LCD_CtrlWrite(0x13, 0x1c00);
	delay(200);
	LCD_CtrlWrite(0x29, 0x4);
	delay(50);
	LCD_CtrlWrite(0x30, 0xb0d);
	LCD_CtrlWrite(0x31, 0x1a26);
	LCD_CtrlWrite(0x32, 0x1d29);
	LCD_CtrlWrite(0x33, 0x291d);
	LCD_CtrlWrite(0x34, 0x261a);
	LCD_CtrlWrite(0x35, 0xd0b);
	LCD_CtrlWrite(0x36, 0x1406);
	LCD_CtrlWrite(0x37, 0x513);
	LCD_CtrlWrite(0x38, 0x706);
	LCD_CtrlWrite(0x39, 0x304);
	LCD_CtrlWrite(0x3a, 0xe05);
	LCD_CtrlWrite(0x3b, 0xe01);
	LCD_CtrlWrite(0x3c, 0x10e);
	LCD_CtrlWrite(0x3d, 0x50e);
	LCD_CtrlWrite(0x3e, 0x403);
	LCD_CtrlWrite(0x3f, 0x607);

	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);
	LCD_CtrlWrite(0x90, 0x16);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x103);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0xf0, 0x5408);
	LCD_CtrlWrite(0xe0, 0x1);
	LCD_CtrlWrite(0xf2, 0xdf);
	LCD_CtrlWrite(0xf3, 0x6d06);
	LCD_CtrlWrite(0xf4, 0x17);
	LCD_CtrlWrite(0xf0, 0x0);
	LCD_CtrlWrite(0x10, 0x12b0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x1bd);
	LCD_CtrlWrite(0x13, 0xc00);
	LCD_CtrlWrite(0x29, 0x4);
	delay(20);
	LCD_CtrlWrite(0x07, 0x112);
	delay(220);
}

void lcd_init_24(void) { /* untested */
	LCD_CtrlWrite(0xe3, 0x3008);
	LCD_CtrlWrite(0xe7, 0x12);
	LCD_CtrlWrite(0xef, 0x1231);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1030);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x10, 0x12b0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x17, 0x1);
	LCD_CtrlWrite(0x12, 0x1bb);
	LCD_CtrlWrite(0x13, 0x1c00);
	delay(200);
	LCD_CtrlWrite(0x29, 0x4);
	delay(50);
	LCD_CtrlWrite(0x30, 0xb0d);
	LCD_CtrlWrite(0x31, 0x1a26);
	LCD_CtrlWrite(0x32, 0x1d29);
	LCD_CtrlWrite(0x33, 0x291d);
	LCD_CtrlWrite(0x34, 0x261a);
	LCD_CtrlWrite(0x35, 0xd0b);
	LCD_CtrlWrite(0x36, 0x1406);
	LCD_CtrlWrite(0x37, 0x513);
	LCD_CtrlWrite(0x38, 0x706);
	LCD_CtrlWrite(0x39, 0x304);
	LCD_CtrlWrite(0x3a, 0xe05);
	LCD_CtrlWrite(0x3b, 0xe01);
	LCD_CtrlWrite(0x3c, 0x10e);
	LCD_CtrlWrite(0x3d, 0x50e);
	LCD_CtrlWrite(0x3e, 0x403);
	LCD_CtrlWrite(0x3f, 0x607);

	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);
	LCD_CtrlWrite(0x90, 0x16);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x103);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0xf0, 0x5408);
	LCD_CtrlWrite(0xe0, 0x1);
	LCD_CtrlWrite(0xf2, 0xdf);
	LCD_CtrlWrite(0xf3, 0x6d06);
	LCD_CtrlWrite(0xf4, 0x17);
	LCD_CtrlWrite(0xf0, 0x0);
	LCD_CtrlWrite(0x10, 0x12b0);
	LCD_CtrlWrite(0x11, 0x6);
	LCD_CtrlWrite(0x12, 0x1bd);
	LCD_CtrlWrite(0x13, 0xc00);
	LCD_CtrlWrite(0x29, 0x4);
	delay(20);
	LCD_CtrlWrite(0x07, 0x112);
	delay(220);
}

/* these inits are for an unknown controller */

void lcd_init_2(void) { /* untested */
	LCD_CtrlWrite(0x07, 0x21);
	LCD_CtrlWrite(0x00, 0x1);
	LCD_CtrlWrite(0x07, 0x23);
	LCD_CtrlWrite(0x10, 0x0);
	delay(30);
	LCD_CtrlWrite(0x07, 0x33);
	LCD_CtrlWrite(0x11, 0x6030);
	LCD_CtrlWrite(0x02, 0x600);
	LCD_CtrlWrite(0x03, 0xa8ae);
	LCD_CtrlWrite(0x0c, 0x6);
	LCD_CtrlWrite(0x0d, 0xd);
	LCD_CtrlWrite(0x0e, 0x3600);
	LCD_CtrlWrite(0x01, 0x2b3f);
	LCD_CtrlWrite(0x05, 0x0);
	LCD_CtrlWrite(0x06, 0x0);
	LCD_CtrlWrite(0x16, 0xef1c);
	LCD_CtrlWrite(0x17, 0x3);
	LCD_CtrlWrite(0x07, 0x233);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x1e, 0xb2);
	LCD_CtrlWrite(0x41, 0x0);
	LCD_CtrlWrite(0x42, 0x0);
	LCD_CtrlWrite(0x48, 0x0);
	LCD_CtrlWrite(0x49, 0x13f);
	LCD_CtrlWrite(0x4a, 0x0);
	LCD_CtrlWrite(0x4b, 0x0);
	LCD_CtrlWrite(0x44, 0xef00);
	LCD_CtrlWrite(0x4e, 0x0);
	LCD_CtrlWrite(0x4f, 0x0);
	LCD_CtrlWrite(0x45, 0x0);
	LCD_CtrlWrite(0x46, 0x13f);
	LCD_CtrlWrite(0x23, 0x0);
	LCD_CtrlWrite(0x24, 0x0);
	delay(200);
	LCD_CtrlWrite(0x28, 0x6);
	LCD_CtrlWrite(0x2f, 0x12be);
	LCD_CtrlWrite(0x30, 0x0);
	LCD_CtrlWrite(0x31, 0x405);
	LCD_CtrlWrite(0x32, 0x0);
	LCD_CtrlWrite(0x33, 0x7);
	LCD_CtrlWrite(0x34, 0x200);
	LCD_CtrlWrite(0x35, 0x303);
	LCD_CtrlWrite(0x36, 0x704);
	LCD_CtrlWrite(0x37, 0x700);
	LCD_CtrlWrite(0x3a, 0x700);
	LCD_CtrlWrite(0x3b, 0x3);
	LCD_CtrlWrite(0x2a, 0x155);
}

void lcd_init_3(void) { /* untested */
	LCD_CtrlWrite(0x00, 0x0);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x03, 0x1010);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0xb03);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x07, 0x101);
	LCD_CtrlWrite(0x10, 0x12b0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x17, 0x1);
	LCD_CtrlWrite(0x12, 0x1bb);
	LCD_CtrlWrite(0x13, 0x1c00);
	delay(200);
	LCD_CtrlWrite(0x29, 0x12);
	delay(50);
	LCD_CtrlWrite(0x30, 0x102);
	LCD_CtrlWrite(0x31, 0xc20);
	LCD_CtrlWrite(0x32, 0xb21);
	LCD_CtrlWrite(0x33, 0x250d);
	LCD_CtrlWrite(0x34, 0x1d0b);
	LCD_CtrlWrite(0x35, 0xa04);
	LCD_CtrlWrite(0x36, 0x1701);
	LCD_CtrlWrite(0x37, 0x617);
	LCD_CtrlWrite(0x38, 0x305);
	LCD_CtrlWrite(0x39, 0xa05);
	LCD_CtrlWrite(0x3a, 0xf04);
	LCD_CtrlWrite(0x3b, 0xf00);
	LCD_CtrlWrite(0x3c, 0xf);
	LCD_CtrlWrite(0x3d, 0x50f);
	LCD_CtrlWrite(0x3e, 0x204);
	LCD_CtrlWrite(0x3f, 0x404);
	
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x13f);
	LCD_SetGRAM(1);
	LCD_SetPDisplay(0);
	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x103);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0xf0, 0x5408);
	LCD_CtrlWrite(0xf3, 0x0);
	LCD_CtrlWrite(0xf4, 0x11);
	LCD_CtrlWrite(0x07, 0x173);
	delay(200);
}

void lcd_init_6(void) { /* untested */
	LCD_CtrlWrite(0x00, 0x1);
	LCD_CtrlWrite(0x01, 0x3b3f);
	LCD_CtrlWrite(0x02, 0x600);
	LCD_CtrlWrite(0x0c, 0x7);
	LCD_CtrlWrite(0x0d, 0x6);
	LCD_CtrlWrite(0x0e, 0x3000);
	LCD_CtrlWrite(0x1e, 0xbb);
	LCD_CtrlWrite(0x03, 0x6a64);
	LCD_CtrlWrite(0x10, 0x0);
	delay(10);
	LCD_CtrlWrite(0x07, 0x33);
	LCD_CtrlWrite(0x0b, 0x5308);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x4f, 0x0);
	LCD_CtrlWrite(0x30, 0x0);
	LCD_CtrlWrite(0x31, 0x400);
	LCD_CtrlWrite(0x32, 0x205);
	LCD_CtrlWrite(0x33, 0x500);
	LCD_CtrlWrite(0x34, 0x103);
	LCD_CtrlWrite(0x35, 0x702);
	LCD_CtrlWrite(0x36, 0x707);
	LCD_CtrlWrite(0x37, 0x102);
	LCD_CtrlWrite(0x3a, 0xf00);
	LCD_CtrlWrite(0x3b, 0x1100);
	LCD_CtrlWrite(0x28, 0x6);
	LCD_CtrlWrite(0x25, 0xe000);
	LCD_CtrlWrite(0x2f, 0x12eb);
	LCD_CtrlWrite(0x26, 0x7000);
	LCD_CtrlWrite(0x20, 0xb0e3);
	LCD_CtrlWrite(0x27, 0x44);
	LCD_CtrlWrite(0x2e, 0x7e45);
}

void lcd_init_7(void) { /* untested */
	LCD_CtrlWrite(0xb0, 0x0);
	LCD_CtrlWrite(0x00, 0x1);
	delay(50);
	LCD_CtrlWrite(0x07, 0x0);
	delay(50);
	LCD_CtrlWrite(0x12, 0x0);
	delay(50);
	LCD_CtrlWrite(0x70, 0x3f00);
	LCD_CtrlWrite(0x08, 0x405);
	LCD_CtrlWrite(0x30, 0x401);
	LCD_CtrlWrite(0x31, 0x206);
	LCD_CtrlWrite(0x32, 0x101);
	LCD_CtrlWrite(0x33, 0x0);
	LCD_CtrlWrite(0x34, 0x706);
	LCD_CtrlWrite(0x35, 0x206);
	LCD_CtrlWrite(0x36, 0x707);
	LCD_CtrlWrite(0x37, 0x0);
	LCD_CtrlWrite(0x38, 0x9);
	LCD_CtrlWrite(0x39, 0x900);
	LCD_CtrlWrite(0x15, 0x1);
	LCD_CtrlWrite(0x10, 0x67b0);
	LCD_CtrlWrite(0x11, 0x47);
	delay(30);
	LCD_CtrlWrite(0x12, 0x117);
	delay(30);
	LCD_CtrlWrite(0x13, 0xa718);
	delay(30);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x4030);
	LCD_CtrlWrite(0x71, 0x1);
	LCD_CtrlWrite(0x90, 0x108);
	LCD_CtrlWrite(0x91, 0x0);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_SetPDisplay(0x13f);
	LCD_SetGRAM(0); /* 60 was never written? */

	LCD_CtrlWrite(0x10, 0x77b0);
	delay(20);
	LCD_CtrlWrite(0x12, 0x1111);
	delay(20);
	LCD_CtrlWrite(0x07, 0x3233);
}

void lcd_init_8(void) { /* untested */
	LCD_CtrlWrite(0x00, 0x0);
	delay(200);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x500);
	LCD_CtrlWrite(0x03, 0x1010);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x07, 0x101);
	delay(10);
	LCD_CtrlWrite(0x10, 0x10b0);
	delay(10);
	LCD_CtrlWrite(0x11, 0x7);
	delay(10);
	LCD_CtrlWrite(0x17, 0x1);
	delay(10);
	LCD_CtrlWrite(0x12, 0x13b);
	delay(10);
	LCD_CtrlWrite(0x13, 0x200);
	delay(10);
	LCD_CtrlWrite(0x29, 0x8);
	LCD_CtrlWrite(0x2a, 0x8);
	delay(100);
	LCD_CtrlWrite(0x30, 0x2);
	LCD_CtrlWrite(0x31, 0x720);
	LCD_CtrlWrite(0x32, 0x924);
	LCD_CtrlWrite(0x33, 0x3f10);
	LCD_CtrlWrite(0x34, 0x3d06);
	LCD_CtrlWrite(0x35, 0x1003);
	LCD_CtrlWrite(0x36, 0xc05);
	LCD_CtrlWrite(0x37, 0x218);
	LCD_CtrlWrite(0x38, 0x6);
	LCD_CtrlWrite(0x39, 0x4);
	LCD_CtrlWrite(0x3a, 0xb05);
	LCD_CtrlWrite(0x3b, 0xb00);
	LCD_CtrlWrite(0x3c, 0x20f);
	LCD_CtrlWrite(0x3d, 0x50f);
	LCD_CtrlWrite(0x3e, 0x203);
	LCD_CtrlWrite(0x3f, 0x501);
	LCD_SetGRAM(0);
	LCD_SetPDisplay(0);
	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x103);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0xf0, 0x5408);
	LCD_CtrlWrite(0xf3, 0x10);
	LCD_CtrlWrite(0xf4, 0x1f);
	LCD_CtrlWrite(0xf0, 0x0);
	delay(100);
	LCD_CtrlWrite(0x07, 0x173);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	LCD_CtrlWrite(0x2b, 0x20);
}

void lcd_init_16(void) { /* untested */
	LCD_CtrlWrite(0x00, 0x0);
	delay(200);
	LCD_CtrlWrite(0x01, 0x0);
	LCD_CtrlWrite(0x02, 0x500);
	LCD_CtrlWrite(0x03, 0x1080);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x07, 0x101);
	delay(10);
	LCD_CtrlWrite(0x10, 0x10b0);
	delay(10);
	LCD_CtrlWrite(0x11, 0x7);
	delay(10);
	LCD_CtrlWrite(0x17, 0x1);
	delay(10);
	LCD_CtrlWrite(0x12, 0x13b);
	delay(10);
	LCD_CtrlWrite(0x13, 0x200);
	delay(10);
	LCD_CtrlWrite(0x29, 0x8);
	LCD_CtrlWrite(0x2a, 0x8);
	delay(100);
	LCD_CtrlWrite(0x30, 0x2);
	LCD_CtrlWrite(0x31, 0x720);
	LCD_CtrlWrite(0x32, 0x924);
	LCD_CtrlWrite(0x33, 0x3f10);
	LCD_CtrlWrite(0x34, 0x3d06);
	LCD_CtrlWrite(0x35, 0x1003);
	LCD_CtrlWrite(0x36, 0xc05);
	LCD_CtrlWrite(0x37, 0x218);
	LCD_CtrlWrite(0x38, 0x6);
	LCD_CtrlWrite(0x39, 0x4);
	LCD_CtrlWrite(0x3a, 0xb05);
	LCD_CtrlWrite(0x3b, 0xb00);
	LCD_CtrlWrite(0x3c, 0x20f);
	LCD_CtrlWrite(0x3d, 0x50f);
	LCD_CtrlWrite(0x3e, 0x203);
	LCD_CtrlWrite(0x3f, 0x501);

	LCD_SetGRAM(0);
	LCD_SetPDisplay(0);
	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x103);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0xf0, 0x5408);
	LCD_CtrlWrite(0xf3, 0x10);
	LCD_CtrlWrite(0xf4, 0x1f);
	LCD_CtrlWrite(0xf0, 0x0);
	delay(100);
	LCD_CtrlWrite(0x07, 0x173);
	LCD_CtrlWrite(0x20, 0x0);
	LCD_CtrlWrite(0x21, 0x0);
	LCD_CtrlWrite(0x2b, 0x20);
}

void lcd_init_22(void) { /* untested */
	LCD_CtrlWrite(0x00, 0x0);
	LCD_CtrlWrite(0x01, 0x0);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1080);
	LCD_CtrlWrite(0x04, 0x0);
	LCD_CtrlWrite(0x08, 0x207);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0c, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x20, 0xef);
	LCD_CtrlWrite(0x21, 0x0);
	LCD_CtrlWrite(0x30, 0x0);
	LCD_CtrlWrite(0x31, 0x1326);
	LCD_CtrlWrite(0x32, 0x1a2a);
	LCD_CtrlWrite(0x33, 0x2a1a);
	LCD_CtrlWrite(0x34, 0x2613);
	LCD_CtrlWrite(0x35, 0x0);
	LCD_CtrlWrite(0x36, 0x1006);
	LCD_CtrlWrite(0x37, 0x610);
	LCD_CtrlWrite(0x38, 0x705);
	LCD_CtrlWrite(0x39, 0x303);
	LCD_CtrlWrite(0x3a, 0xe05);
	LCD_CtrlWrite(0x3b, 0xe01);
	LCD_CtrlWrite(0x3c, 0x10e);
	LCD_CtrlWrite(0x3d, 0x50e);
	LCD_CtrlWrite(0x3e, 0x203);
	LCD_CtrlWrite(0x3f, 0x507);

	LCD_SetGRAM(0);
	LCD_SetPDisplay(0);
	LCD_CtrlWrite(0x90, 0x14);
	LCD_CtrlWrite(0x92, 0x500);
	LCD_CtrlWrite(0x93, 0x0);
	LCD_CtrlWrite(0x95, 0x110);
	LCD_CtrlWrite(0x97, 0x0);
	LCD_CtrlWrite(0x98, 0x0);
	LCD_CtrlWrite(0xf0, 0x5408);
	LCD_CtrlWrite(0xe0, 0x1);
	LCD_CtrlWrite(0xf2, 0xdf);
	LCD_CtrlWrite(0xf3, 0x20f);
	LCD_CtrlWrite(0xf4, 0x1f);
	LCD_CtrlWrite(0xf0, 0x0);
	LCD_CtrlWrite(0x10, 0x15b0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x1be);
	LCD_CtrlWrite(0x13, 0x1000);
	LCD_CtrlWrite(0x29, 0x2);
	LCD_CtrlWrite(0x07, 0x112);
	delay(200);
}

/* Init routines for HX8347 controller
   see https://engineering.purdue.edu/477grp2/klutzke_nb_files/HX8347-A_AN_v01_070726.pdf */

void lcd_init_hx8347a(void) { /* untested */
	/* set gamma */
	LCD_CtrlWrite(0x46, 0x95);
	LCD_CtrlWrite(0x47, 0x51);
	LCD_CtrlWrite(0x48, 0x0);
	LCD_CtrlWrite(0x49, 0x36);
	LCD_CtrlWrite(0x4a, 0x11);
	LCD_CtrlWrite(0x4b, 0x66);
	LCD_CtrlWrite(0x4c, 0x14);
	LCD_CtrlWrite(0x4d, 0x77);
	LCD_CtrlWrite(0x4e, 0x13);
	LCD_CtrlWrite(0x4f, 0x4c);
	LCD_CtrlWrite(0x50, 0x46);
	LCD_CtrlWrite(0x51, 0x46);

	/* 240x320 window setting */
	LCD_CtrlWrite(0x02, 0x0);  /* column address start2 */
	LCD_CtrlWrite(0x03, 0x0);  /* column address start1 */
	LCD_CtrlWrite(0x04, 0x0);  /* column address end2 */
	LCD_CtrlWrite(0x05, 0xef); /* column address end1 */
	LCD_CtrlWrite(0x06, 0x0);  /* row address start2 */
	LCD_CtrlWrite(0x07, 0x0);  /* row address start1 */
	LCD_CtrlWrite(0x08, 0x1);  /* row address end2 */
	LCD_CtrlWrite(0x09, 0x3f); /* row address end1 */
	
	/* Display setting */
	LCD_CtrlWrite(0x90, 0x7f); /* SAP=0111 1111 */
	LCD_CtrlWrite(0x01, 0x6);  /* DMON=0, INVON=1, NORON=1, PTLON=0 */
	LCD_CtrlWrite(0x16, 0x48); /* MY=0, MX=0, MV=0, ML=1, BGR=0, TEON=0 */

	LCD_CtrlWrite(0x23, 0x95); /* N_DC=1001 0101 */
	LCD_CtrlWrite(0x24, 0x95); /* PI_DC=1001 0101 */
	LCD_CtrlWrite(0x25, 0xff); /* I_DC=1111 1111 */
	
	LCD_CtrlWrite(0x27, 0x6); /* N_BP=0000 0110 */
	LCD_CtrlWrite(0x28, 0x6); /* N_FP=0000 0110 */
	LCD_CtrlWrite(0x29, 0x6); /* PI_BP=0000 0110 */
	LCD_CtrlWrite(0x2a, 0x6); /* PI_FP=0000 0110 */
	LCD_CtrlWrite(0x2c, 0x6); /* I_BP=0000 0110 */
	LCD_CtrlWrite(0x2d, 0x6); /* N_BP=0000 0110 */
	
	LCD_CtrlWrite(0x3a, 0x1); /* N_RTN=0000, N_NW=001 */
	LCD_CtrlWrite(0x3b, 0x1); /* PI_RTN=0000, PI_NW=001 */
	LCD_CtrlWrite(0x3c, 0xf0); /* I_RTN=1111, I_NW=000 */
	LCD_CtrlWrite(0x3d, 0x0); /* DIV=00 */
	delay(20);
	LCD_CtrlWrite(0x10, 0xa6);

	/* power supply setting */
	LCD_CtrlWrite(0x19, 0x49); /* CADJ=0100, CUADJ=100(FR:60Hz), OSD_EN=1 */
	LCD_CtrlWrite(0x93, 0xc);  /* RADJ=1100 */
	delay(10);
	LCD_CtrlWrite(0x20, 0x40); /* BT=0100 */
	LCD_CtrlWrite(0x1d, 0x7); /* VC1=111 */
	LCD_CtrlWrite(0x1e, 0x0); /* VC3=000 */
	LCD_CtrlWrite(0x1f, 0x4); /* VRH=0100 */

	/* VCOM setting */
	LCD_CtrlWrite(0x44, 0x2c); /* VCM */
	LCD_CtrlWrite(0x45, 0x10); /* VDV */
	delay(50);
	LCD_CtrlWrite(0x1c, 0x6); /* AP */
	delay(10);
	LCD_CtrlWrite(0x43, 0x80); /* set VCOMG=1 */
	delay(20);
	LCD_CtrlWrite(0x1b, 0x18); /* GASENB=0, PON=1, DK=1, XDK=0, VLCD_TRI=0, STB=0 */
	delay(20);
	LCD_CtrlWrite(0x1b, 0x10); /* GASENB=0, PON=1, DK=0, XDK=0, VLCD_TRI=0, STB=0 */
	delay(20);
	LCD_CtrlWrite(0x26, 0x4); /* GON=0, DTE=0, D=01 */
	delay(100);
	LCD_CtrlWrite(0x26, 0x24); /* GON=1, DTE=0, D=01 */
	LCD_CtrlWrite(0x26, 0x2c); /* GON=1, DTE=0, D=11 */
	delay(100);
	LCD_CtrlWrite(0x26, 0x3c); /* //GON=1, DTE=1, D=11 */
	
	LCD_CtrlWrite(0x35, 0x38); /* EQS=38h */
	LCD_CtrlWrite(0x36, 0x78); /* EQP=78h */
	LCD_CtrlWrite(0x3e, 0x38); /* SON=38h */
	LCD_CtrlWrite(0x40, 0xf); /* GDON=0Fh */
	LCD_CtrlWrite(0x41, 0xf0); /* GDOFF */
	LCD_CtrlWrite(0x57, 0x2); /* Test_Mode Enable */
	LCD_CtrlWrite(0x56, 0x84);
	LCD_CtrlWrite(0x57, 0x0); /* Test_Mode Disable */
	LCD_CtrlWrite(0x70, 0x46);
	delay(200);
}

void lcd_init_hx8347b(void) { /* untested */
	/* set gamma */
	LCD_CtrlWrite(0x46, 0x34);
	LCD_CtrlWrite(0x47, 0x43);
	LCD_CtrlWrite(0x48, 0x44);
	LCD_CtrlWrite(0x49, 0x27);
	LCD_CtrlWrite(0x4a, 0x0);
	LCD_CtrlWrite(0x4b, 0x77);
	LCD_CtrlWrite(0x4c, 0x5);
	LCD_CtrlWrite(0x4d, 0x33);
	LCD_CtrlWrite(0x4e, 0x32);
	LCD_CtrlWrite(0x4f, 0x36);
	LCD_CtrlWrite(0x50, 0x3c);
	LCD_CtrlWrite(0x51, 0x43);

	/* 240x320 window setting */
	LCD_CtrlWrite(0x02, 0x0);  /* column address start2 */
	LCD_CtrlWrite(0x03, 0x0);  /* column address start1 */
	LCD_CtrlWrite(0x04, 0x0);  /* column address end2 */
	LCD_CtrlWrite(0x05, 0xef); /* column address end1 */
	LCD_CtrlWrite(0x06, 0x0);  /* row address start2 */
	LCD_CtrlWrite(0x07, 0x0);  /* row address start1 */
	LCD_CtrlWrite(0x08, 0x1);  /* row address end2 */
	LCD_CtrlWrite(0x09, 0x3f); /* row address end1 */
	
	LCD_CtrlWrite(0x23, 0x95); /* N_DC=1001 0101 */
	LCD_CtrlWrite(0x24, 0x95); /* PI_DC=1001 0101 */
	LCD_CtrlWrite(0x25, 0xff); /* I_DC=1111 1111 */
	
	LCD_CtrlWrite(0x28, 0x2); /* N_FP=0000 0010 */
	LCD_CtrlWrite(0x29, 0x2); /* PI_BP=0000 0010 */
	LCD_CtrlWrite(0x2a, 0x2); /* PI_FP=0000 0010 */
	LCD_CtrlWrite(0x2c, 0x2); /* I_BP=0000 0010 */
	LCD_CtrlWrite(0x2d, 0x2); /* N_BP=0000 0010 */
	
	LCD_CtrlWrite(0x3a, 0x1); /* N_RTN=0000, N_NW=001 */
	LCD_CtrlWrite(0x3b, 0x1); /* PI_RTN=0000, PI_NW=001 */
	LCD_CtrlWrite(0x3c, 0xf0); /* I_RTN=1111, I_NW=000 */
	LCD_CtrlWrite(0x3d, 0x0); /* DIV=00 */
	delay(20);
	LCD_CtrlWrite(0x19, 0x7f);
	delay(20);
	LCD_CtrlWrite(0x20, 0x80);
	LCD_CtrlWrite(0x21, 0x0);
	LCD_CtrlWrite(0x1d, 0x47);
	LCD_CtrlWrite(0x1e, 0x0);
	LCD_CtrlWrite(0x1f, 0x3);
	LCD_CtrlWrite(0x44, 0x48);
	LCD_CtrlWrite(0x45, 0xe);
	delay(10);
	LCD_CtrlWrite(0x1c, 0x4);
	delay(20);
	LCD_CtrlWrite(0x1b, 0x14);
	delay(40);
	LCD_CtrlWrite(0x43, 0x80);
	delay(100);
	LCD_CtrlWrite(0x30, 0x8);
	delay(40);
	LCD_CtrlWrite(0x26, 0x4);
	delay(40);
	LCD_CtrlWrite(0x26, 0x24);
	delay(40);
	LCD_CtrlWrite(0x26, 0x2c);
	delay(40);
	LCD_CtrlWrite(0x26, 0x3c);
	LCD_CtrlWrite(0x01, 0x6);
	LCD_CtrlWrite(0x16, 0x58);
	delay(200);
}

void lcd_init_27_31(void) { /* untested */
	LCD_CtrlWrite(0x00, 0x0);
	LCD_CtrlWrite(0x07, 0x0);
	LCD_CtrlWrite(0xa4, 0x1);
	delay(320);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x700);
	LCD_CtrlWrite(0x03, 0x1230);
	LCD_CtrlWrite(0x08, 0x808);
	LCD_CtrlWrite(0x09, 0x600);
	LCD_CtrlWrite(0x0a, 0x0);
	LCD_CtrlWrite(0x0d, 0x0);

	LCD_SetGRAM(0);
	LCD_CtrlWrite(0x90, 0x10);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x93, 0x10);
	LCD_CtrlWrite(0x30, 0x707);
	LCD_CtrlWrite(0x31, 0x407);
	LCD_CtrlWrite(0x32, 0x203);
	LCD_CtrlWrite(0x33, 0x303);
	LCD_CtrlWrite(0x34, 0x303);
	LCD_CtrlWrite(0x35, 0x202);
	LCD_CtrlWrite(0x36, 0x1f1f);
	LCD_CtrlWrite(0x37, 0x707);
	LCD_CtrlWrite(0x38, 0x407);
	LCD_CtrlWrite(0x39, 0x203);
	LCD_CtrlWrite(0x3a, 0x303);
	LCD_CtrlWrite(0x3b, 0x303);
	LCD_CtrlWrite(0x3c, 0x202);
	LCD_CtrlWrite(0x3d, 0x1f10);
	LCD_CtrlWrite(0x07, 0x1);
	delay(1600);
	LCD_CtrlWrite(0x17, 0x1);
	delay(1600);
	LCD_CtrlWrite(0x10, 0x13b0);
	LCD_CtrlWrite(0x11, 0x7);
	LCD_CtrlWrite(0x12, 0x130);
	LCD_CtrlWrite(0x13, 0x500);
	LCD_CtrlWrite(0x29, 0x0);
	delay(1600);
	LCD_CtrlWrite(0x12, 0x13a);
	delay(19200);
	LCD_CtrlWrite(0x07, 0x21);
	delay(1600);
	LCD_CtrlWrite(0x07, 0x61);
	delay(1600);
	LCD_CtrlWrite(0x07, 0x173);
	delay(200);
}

void lcd_init_30(void) { /* untested */
	LCD_CtrlWrite(0x28, 0x6);
	LCD_CtrlWrite(0x07, 0x21);
	LCD_CtrlWrite(0x00, 0x1);
	delay(30);
	LCD_CtrlWrite(0x07, 0x23);
	LCD_CtrlWrite(0x10, 0x0);
	delay(30);
	LCD_CtrlWrite(0x07, 0x33);
	LCD_CtrlWrite(0x01, 0x2b3f);
	LCD_CtrlWrite(0x02, 0x600);
	LCD_CtrlWrite(0x11, 0x6830);
	LCD_CtrlWrite(0x03, 0xa6a8);
	LCD_CtrlWrite(0x0f, 0x0);
	LCD_CtrlWrite(0x0e, 0x3000);
	LCD_CtrlWrite(0x1e, 0xae);
	LCD_CtrlWrite(0x0c, 0x5);
	LCD_CtrlWrite(0x0d, 0x8);
	LCD_CtrlWrite(0x0b, 0x5308);
	LCD_CtrlWrite(0x25, 0xe000);
	LCD_CtrlWrite(0x3f, 0xbb84);
	LCD_CtrlWrite(0x27, 0x567);
	LCD_CtrlWrite(0x20, 0x316c);
	LCD_CtrlWrite(0x30, 0x7);
	LCD_CtrlWrite(0x31, 0x3);
	LCD_CtrlWrite(0x32, 0x300);
	LCD_CtrlWrite(0x33, 0x104);
	LCD_CtrlWrite(0x34, 0x707);
	LCD_CtrlWrite(0x35, 0x2);
	LCD_CtrlWrite(0x36, 0x503);
	LCD_CtrlWrite(0x37, 0x502);
	LCD_CtrlWrite(0x3a, 0x1000);
	LCD_CtrlWrite(0x3b, 0x8);
	LCD_CtrlWrite(0x44, 0xef00);
	LCD_CtrlWrite(0x45, 0x0);
	LCD_CtrlWrite(0x46, 0x13f);
	LCD_CtrlWrite(0x4e, 0x0);
	LCD_CtrlWrite(0x4f, 0x0);
}

void lcd_init_37(void) { /* untested */
	LCD_CtrlWrite(0xb0, 0x4);
	LCD_CtrlWrite(0x00, 0x1);
	delay(8000);
	LCD_CtrlWrite(0x07, 0x0);
	delay(8000);
	LCD_CtrlWrite(0x12, 0x0);
	delay(8000);
	LCD_CtrlWrite(0x70, 0x2700);
	LCD_CtrlWrite(0x08, 0x405);
	LCD_CtrlWrite(0x30, 0x0);
	LCD_CtrlWrite(0x31, 0x505);
	LCD_CtrlWrite(0x32, 0x704);
	LCD_CtrlWrite(0x33, 0x6);
	LCD_CtrlWrite(0x34, 0x100);
	LCD_CtrlWrite(0x35, 0x2);
	LCD_CtrlWrite(0x36, 0x707);
	LCD_CtrlWrite(0x37, 0x701);
	LCD_CtrlWrite(0x38, 0x700);
	LCD_CtrlWrite(0x39, 0x800);
	LCD_CtrlWrite(0x15, 0x1);
	LCD_CtrlWrite(0x10, 0x66b0);
	LCD_CtrlWrite(0x11, 0x7);
	delay(3200);
	LCD_CtrlWrite(0x12, 0x108);
	delay(4800);
	LCD_CtrlWrite(0x12, 0x118);
	delay(4800);
	LCD_CtrlWrite(0x13, 0x9d14);
	delay(4800);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x02, 0x100);
	LCD_CtrlWrite(0x03, 0x30);
	LCD_CtrlWrite(0x71, 0x0);
	LCD_CtrlWrite(0x90, 0xd);
	LCD_CtrlWrite(0x91, 0x0);
	LCD_CtrlWrite(0x92, 0x0);
	LCD_CtrlWrite(0x09, 0x0);
	LCD_SetPDisplay(0x13f);
	LCD_SetGRAM(0); /* 60 was never written */
	LCD_CtrlWrite(0x10, 0x76b0);
	delay(3200);
	LCD_CtrlWrite(0x07, 0x1);
	delay(3200);
	LCD_CtrlWrite(0x07, 0x21);
	LCD_CtrlWrite(0x12, 0x1118);
	delay(3200);
	LCD_CtrlWrite(0x07, 0x233);
}

void lcd_init_default(void) { /* untested */
	LCD_CtrlWrite(0x00, 0x1);
	delay(64000);
	LCD_CtrlWrite(0x01, 0x100);
	LCD_CtrlWrite(0x10, 0x1790);

	LCD_SetGRAM(1);
	LCD_CtrlWrite(0x46, 0x2);
	LCD_CtrlWrite(0x13, 0x8018);
	LCD_CtrlWrite(0x12, 0x80fe);
	LCD_CtrlWrite(0x02, 0x500);
	LCD_CtrlWrite(0x03, 0x30);
	LCD_CtrlWrite(0x30, 0x303);
	LCD_CtrlWrite(0x31, 0x303);
	LCD_CtrlWrite(0x32, 0x303);
	LCD_CtrlWrite(0x33, 0x300);
	LCD_CtrlWrite(0x34, 0x3);
	LCD_CtrlWrite(0x35, 0x303);
	LCD_CtrlWrite(0x36, 0x1400);
	LCD_CtrlWrite(0x37, 0x303);
	LCD_CtrlWrite(0x38, 0x303);
	LCD_CtrlWrite(0x39, 0x303);
	LCD_CtrlWrite(0x3a, 0x300);
	LCD_CtrlWrite(0x3b, 0x3);
	LCD_CtrlWrite(0x3c, 0x303);
	LCD_CtrlWrite(0x3d, 0x1400);
	LCD_CtrlWrite(0x92, 0x200);
	LCD_CtrlWrite(0x93, 0x303);
	LCD_CtrlWrite(0x90, 0x813);
	LCD_CtrlWrite(0x07, 0x173);
}

/* these are just weird */

void lcd_init_weird1(void) { /* untested */
	LCD_AddrWrite(0x11);
	delay(120);
	LCD_CtrlWrite(0xb1, 0x28);
	LCD_CmdWrite(0x2);
	LCD_CmdWrite(0x2);
	LCD_CtrlWrite(0xb2, 0x2a);
	LCD_CmdWrite(0x2);
	LCD_CmdWrite(0x2);
	LCD_AddrWrite(0xbc);
	delay(50);
	LCD_CtrlWrite(0xc2, 0x2);
	LCD_CmdWrite(0xd6);
	LCD_CmdWrite(0x86);
	LCD_CmdWrite(0x0);
	LCD_CmdWrite(0x0);
	LCD_CtrlWrite(0xc3, 0x1);
	LCD_CmdWrite(0x66);
	LCD_CmdWrite(0x1);
	LCD_CmdWrite(0x0);
	LCD_CmdWrite(0x0);
	delay(50);
	LCD_CtrlWrite(0xf4, 0xff);
	LCD_CmdWrite(0x3f);
	delay(25);
	LCD_CtrlWrite(0xfb, 0x7f);
	LCD_CtrlWrite(0xc5, 0xc0);
	LCD_CmdWrite(0x19);
	LCD_CtrlWrite(0xc6, 0x26);
	LCD_CmdWrite(0x0);
	delay(50);
	LCD_CtrlWrite(0xc0, 0x0);
	LCD_CtrlWrite(0x35, 0x0);
	delay(50);
	LCD_CtrlWrite(0xb6, 0x2);
	LCD_CmdWrite(0x4);
	LCD_CtrlWrite(0x3a, 0x5);
	delay(200);
	LCD_AddrWrite(0x29);
	LCD_CtrlWrite(0x2a, 0x0);
	LCD_CmdWrite(0x0);
	LCD_CmdWrite(0x0);
	LCD_CmdWrite(0xef);
	LCD_CtrlWrite(0x2b, 0x0);
	LCD_CmdWrite(0x0);
	LCD_CmdWrite(0x1);
	LCD_CmdWrite(0x3f);
	LCD_CtrlWrite(0x36, 0x10);
	LCD_AddrWrite(0x2c);
}

void lcd_init_weird2(void) { /* untested */
	LCD_AddrWrite(0x11);
	delay(5000);
	LCD_CtrlWrite(0xb1, 0x16);
	LCD_CmdWrite(0x3);
	LCD_CmdWrite(0x2);
	LCD_CtrlWrite(0xb2, 0x28);
	LCD_CmdWrite(0x4);
	LCD_CmdWrite(0x2);
	LCD_CtrlWrite(0xb3, 0x28);
	LCD_CmdWrite(0x4);
	LCD_CmdWrite(0x2);
	LCD_CmdWrite(0x28);
	LCD_CmdWrite(0x4);
	LCD_CmdWrite(0x2);
	LCD_CtrlWrite(0xb4, 0x6);
	LCD_CtrlWrite(0xb6, 0x3);
	LCD_CmdWrite(0x4);
	delay(100);
	LCD_CtrlWrite(0xc0, 0x5);
	LCD_CtrlWrite(0xc1, 0xbb);
	LCD_CmdWrite(0x0);
	LCD_CtrlWrite(0xc2, 0x1);
	LCD_CmdWrite(0xdd);
	LCD_CmdWrite(0x8d);
	LCD_CmdWrite(0xdd);
	LCD_CmdWrite(0xd);
	LCD_CmdWrite(0x3);
	LCD_CmdWrite(0x0);
	LCD_CtrlWrite(0xc3, 0x1);
	LCD_CmdWrite(0xcc);
	LCD_CmdWrite(0xc);
	LCD_CmdWrite(0xcc);
	LCD_CmdWrite(0xc);
	LCD_CmdWrite(0x0);
	LCD_CtrlWrite(0xc4, 0x1);
	LCD_CmdWrite(0xed);
	LCD_CmdWrite(0xd);
	LCD_CmdWrite(0x33);
	LCD_CmdWrite(0x3);
	LCD_CmdWrite(0x0);
	LCD_CtrlWrite(0xc5, 0x2b);
	LCD_CmdWrite(0x21);
	LCD_CtrlWrite(0xc6, 0x18);
	LCD_CmdWrite(0x0);
	LCD_CtrlWrite(0xcc, 0x1);
	delay(100);
	LCD_CtrlWrite(0xe0, 0x1);
	LCD_CmdWrite(0xb);
	LCD_CmdWrite(0x19);
	LCD_CmdWrite(0x1c);
	LCD_CmdWrite(0x1b);
	LCD_CmdWrite(0x19);
	LCD_CmdWrite(0x18);
	LCD_CmdWrite(0x19);
	LCD_CmdWrite(0x1a);
	LCD_CmdWrite(0xd);
	LCD_CmdWrite(0x1);
	LCD_CmdWrite(0x2);
	LCD_CmdWrite(0x2);
	LCD_CtrlWrite(0xe1, 0x1);
	LCD_CmdWrite(0xb);
	LCD_CmdWrite(0x19);
	LCD_CmdWrite(0x1c);
	LCD_CmdWrite(0x1b);
	LCD_CmdWrite(0x19);
	LCD_CmdWrite(0x18);
	LCD_CmdWrite(0x19);
	LCD_CmdWrite(0x1a);
	LCD_CmdWrite(0xd);
	LCD_CmdWrite(0x1);
	LCD_CmdWrite(0x2);
	LCD_CmdWrite(0x2);
	LCD_CtrlWrite(0x35, 0x0);
	LCD_CtrlWrite(0x3a, 0x55);
	LCD_CtrlWrite(0x36, 0x0);
	LCD_CtrlWrite(0x2a, 0x0);
	LCD_CmdWrite(0x0);
	LCD_CmdWrite(0x0);
	LCD_CmdWrite(0xef);
	LCD_CtrlWrite(0x2b, 0x0);
	LCD_CmdWrite(0x0);
	LCD_CmdWrite(0x1);
	LCD_CmdWrite(0x3f);
	delay(10);
	LCD_AddrWrite(0x29);
	LCD_AddrWrite(0x2c);
	delay(100);
}

void master_lcd_init(int type)
{
	switch(type) {
		case 1:
			lcd_init_1();
			break;
		case 2:
			lcd_init_2();
			break;
		case 3:
			lcd_init_3();
			delay(100);
			lcd_init_3();
			break;
		case 4:
			lcd_init_weird1();
			break;
		case 5:
			lcd_init_hx8347a();
			break;
		case 6:
			lcd_init_6();
			break;
		case 7:
			lcd_init_7();
			break;
		case 8:
			lcd_init_8();
			delay(100);
			lcd_init_8();
			break;
		case 9:
			lcd_init_9();
			break;
		case 10:
			lcd_init_10();
			break;
		case 11:
			lcd_init_11();
			break;
		case 12:
			lcd_init_12();
			break;
		case 13:
			lcd_init_13();
			break;
		case 14:
			lcd_init_14();
			break;
		case 15:
			lcd_init_weird2();
			lcd_init_weird2();
			break;
		case 16:
			lcd_init_16();
			delay(100);
			lcd_init_16();
			break;
		case 17:
			lcd_init_17();
			break;
		case 18:
			lcd_init_18();
			break;
		case 19:
			lcd_init_hx8347b();
			break;
		case 20:
			lcd_init_20();
			break;
		case 21:
			lcd_init_21();
			break;
		case 22:
			lcd_init_22();
			break;
		case 23:
			lcd_init_23();
			break;
		case 24:
			lcd_init_24();
			break;
		case 25:
			lcd_init_25();
			break;
		case 26:
		case 29:
			lcd_init_26_29();
			break;
		case 27:
		case 31:
			lcd_init_27_31();
			break;
		case 30:
			lcd_init_30();
			break;
		case 32:
			lcd_init_32();
			break;
		case 33:
			lcd_init_33();
			break;
		case 34:
			lcd_init_34();
			break;
		case 35:
			lcd_init_35();
			break;
		case 36:
			lcd_init_36();
			break;
		case 37:
			lcd_init_37();
			break;
		case 38:
			lcd_init_38();
			break;
		case 39:
			lcd_init_39();
			break;
		case 40:
			lcd_init_40();
			break;
		case 41:
			LCD_Init_3b();
			break;
		case 42:
			lcd_init_1b();
			break;
		default:
			lcd_init_default();
			break;
	}
	LCD_AddrWrite(0x22);
}
